import dt from '@dt/dt'
import ruleOpt from '@/biz/option/rule.js'
import cityMgr from '@/biz/option/city'

let _this = null

function special(_this) {
  let opt = [{
    title: '案场状态',
    placeholder: '请选择案场状态',
    key: 'status',
    col: 12,
    select: {
      options: dt.dictInfo().buildStatus,
    },
    rules: [{
      required: true,
      message: '请选择案场状态',
      trigger: 'blur'
    }]
  }]
  return _this.flag == 'special' ? opt : []
}

function p1() {
  let opt = [{
    title: '预计开盘日期',
    placeholder: '请选择预计开盘日期',
    key: 'expectedOpenTime',
    col: 12,
    date: {
      type: 'date'
    },
    rules: [{
      required: true,
      message: '请选择预计开盘日期',
      trigger: 'blur'
    }]
  }, {
    title: '进场时间',
    placeholder: '请选择进场时间',
    key: 'enterDate',
    col: 12,
    date: {
      type: 'date'
    },
    rules: [{
      required: true,
      message: '请选择进场时间',
      trigger: 'blur'
    }]
  }]
  return opt
}

function p2() {
  let opt = [{
    title: '合作模式',
    placeholder: '请选择合作模式',
    key: 'cooperationMode',
    col: 12,
    select: {
      options: dt.dictInfo().cooperationModeAttrSort,
    },
    rules: [{
      required: true,
      message: '请选择合作模式',
      trigger: 'blur'
    }]
  }, {
    key: 'agencyRateMin',
    title: '代理费率',
    group: [{
      key: 'agencyRateMin',
      col: 11,
      input: {
        appendTxt: '%',
      },
    }, {
      placeholder: '至',
      col: 2,
      text: {
        textAlign: 'center',
      }
    }, {
      key: 'agencyRateMax',
      col: 11,
      input: {
        appendTxt: '%',
      }
    }],
    rules: [
      {
        required: true,
        message: '请填写代理费',
        trigger: 'blur',
      },
      ruleOpt.check('请填写完整的区间值', () => {
        return (_this.info.agencyRateMax == null && _this.info.agencyRateMin !=
            null) ||
          (_this.info.agencyRateMax != null && _this.info.agencyRateMin == null)
      }, 'blur'),
      ruleOpt.check('不允许输入负数', () => {
        return _this.info.agencyRateMax < 0 || _this.info.agencyRateMin < 0
      }, 'blur'),
      ruleOpt.check('起始值须小于结束值', () => {
        return Number(_this.info.agencyRateMax) < Number(_this.info.agencyRateMin)
      }, 'blur'),
      ruleOpt.check('最多保留四位小数', (val) => {
        let reg = /^[\d,-]?\d+(\.\d{1,4}){0,1}$/
        return !reg.test(val) ? true : false
      }, 'blur'),
    ]
  }]
  return opt
}

function p3() {
  let opt = [{
    title: '开发商',
    placeholder: '请输入开发商',
    key: 'developers',
    col: 12,
    input: {},
  }, {
    title: '开发商简称',
    placeholder: '请输入开发商简称',
    key: 'developerAbbreviation',
    col: 12,
    input: {},
  }, ]
  return opt
}

function p4() {
  let cashDeposit = {
    title: '保证金金额',
    placeholder: '请输入保证金金额',
    key: 'securityFundMoney',
    visible: _this.info.isSecurityFund == '1',
    col: 12,
    input: {
      appendTxt: '元',
    },
    rules: [
      {
        required: true,
        message: '请输入保证金金额',
        trigger: 'blur',
        type: 'string'
      },
      ruleOpt.twoDecimal(),
    ]
  }
  let opt = [{
    title: '是否有保证金',
    key: 'isSecurityFund',
    col: 12,
    radio: {
      options: [{ key: '1', value: '是' }, { key: '0', value: '否' }],
    },
    change: (res) => {
      cashDeposit.visible = res.value
      _this.info.securityFundMoney = ''
    },
    rules: [{
      required: true,
      message: '请选择是否有保证金',
      trigger: 'blur'
    }]
  }, cashDeposit]
  return opt
}

function p5() {
  let opt = [{
    title: '项目接电规则',
    placeholder: '请输入项目接电规则',
    key: 'projectPowerConnectionRules',
    col: 12,
    input: { maxlength: 100 },
  }, {
    title: '项目接待规则',
    placeholder: '请输入项目接待规则',
    key: 'projectReceptionRules',
    col: 12,
    input: { maxlength: 100 },
  }, ]
  return opt
}

function p6() {
  let opt = [{
    title: '售楼处电话',
    placeholder: '请输入售楼处电话',
    key: 'salesOfficePhone',
    col: 12,
    input: { maxlength: 20 },
  }, ]
  return opt
}

function p7() {
  let opt = [{
    title: '总货量(面积)',
    key: 'totalArea',
    col: 12,
    input: {
      appendTxt: '㎡',
      maxlength: 20
    },
    rules: [
      ruleOpt.check('数值只能保留两位小数', (value) => {
        if (!value) return false;
        let reg = /^[\d,-]?\d+(\.\d{1,2}){0,1}$/
        return !reg.test(value)
      })
    ]
  }, {
    title: '总货值(价值)',
    key: 'totalPrice',
    col: 12,
    input: {
      appendTxt: '亿元',
      maxlength: 20
    },
    rules: [
      ruleOpt.check('数值只能保留两位小数', (value) => {
        if (!value) return false;
        let reg = /^[\d,-]?\d+(\.\d{1,2}){0,1}$/
        return !reg.test(value)
      })
    ]
  }]
  return opt
}

function p8() {
  let opt = [{
    title: '单边货量(面积)',
    key: 'unitArea',
    col: 12,
    input: {
      appendTxt: '㎡',
      maxlength: 20
    },
    rules: [
      ruleOpt.check('数值只能保留两位小数', (value) => {
        if (!value) return false;
        let reg = /^[\d,-]?\d+(\.\d{1,2}){0,1}$/
        return !reg.test(value)
      })
    ]
  }, {
    title: '单边货值(价值)',
    key: 'unitPrice',
    col: 12,
    input: {
      appendTxt: '亿元',
      maxlength: 20
    },
    rules: [
      ruleOpt.check('数值只能保留两位小数', (value) => {
        if (!value) return false;
        let reg = /^[\d,-]?\d+(\.\d{1,2}){0,1}$/
        return !reg.test(value)
      })
    ]
  }]
  return opt
}

function p9() {
  let opt = [{
    title: '售楼处地址',
    placeholder: '请输入售楼处地址',
    key: 'address',
    col: 24,
    input: { maxlength: 200 },
    rules: [{
      required: true,
      message: '请输入售楼处地址',
      trigger: 'blur'
    }]
  }, ]
  return opt
}

function p10() {
  let opt = [{
    title: '详细地址',
    placeholder: '请输入详细地址',
    key: 'detailedAddress',
    col: 24,
    input: { maxlength: 200 },
    rules: [{
      required: true,
      message: '请输入详细地址',
      trigger: 'blur'
    }]
  }]
  return opt
}

function options(vm) {
  _this = vm
  let arr = [
    special(_this),
    p1(),
    p2(),
    p3(),
    p4(),
    p5(),
    cityMgr.city({ info: _this.info, isView: false, labelWidth: 130 }),
    p6(),
    p7(),
    p8(),
    p9(),
    p10()
  ]
  return arr
}

export default {
  options
}